<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<link href="/assets/css/style.css?v=2" rel="stylesheet">
	<link href="/assets/css/style0.css?v=2" rel="stylesheet">
	<link href="/assets/css/style1.css?v=2" rel="stylesheet">
	<link href="/assets/css/style2.css?v=2" rel="stylesheet">
	<style>
       .foottext{
		   position: absolute;
		   bottom: 20px;
		   color: #F4F4F4;
		   z-index: 100;
		   width: 100%;
		   text-align: center;
	   }
	   .coupon-item .item-left{
		   display: flex;
		   color: #dc0017;
		   align-items: center;
		   justify-content: center;
		   font-size: 30px;
		   font-weight: bold;
	   }
	   .coupon-item .item-left .money{
		   font-size: 6vw;
		   margin-bottom: 15px;
	   }
    </style>
    <title>丽华快餐-领取现金券</title>
</head>
<body>
	<div id="root" srtle="background:#c90825">
		<div class="router-wrapper">
			<div class="page-wrapper forward-enter-done">
				<div class="invite-result " style="display: block; background-color: #dc0017;">
					<div class="banner">
						<img class="banner-pic" alt="" src="/assets/img/vvv2.png?v=2"></div>
						<div class="body adjust"><div class="coupon-ad"></div>
						<div class="coupon-list" style="margin-top: 0px;">
							{foreach name="list" item="v"}
							<div>
								<div>
									<div class="coupon-item our-coupon">
										<div class="item-left">
											<div class="money">{$v['price']}元</div>
										</div>
										<div class="item-middle">
											<div class="top">
												<div class="title">无门槛现金券</div>
											</div>
											<div class="date">有效日期:</div>
											<div class="desc">{$v['start_date']} 至 {$v['end_date']}</div>
										</div>
										<div class="item-right">
											<span>立即<br>使用</span>
										</div>
									</div>
								</div>
							</div>
							{/foreach}
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="foottext">常州丽华快餐集团有限公司</div>

<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>
	var canGetCode = true;
    var setTimeOut = null;
	var t = null;
	var android_scheme_url = "lihuaapp://";
	var ios_appstore_url = "https://apps.apple.com/cn/app/%E4%B8%BD%E5%8D%8E%E5%BF%AB%E9%A4%90/id628351424";//
	var android_downloadurl = "";
	$(function(){
		
		//判断当前所在的平台
		var ua = navigator.userAgent.toLowerCase();
		var iOS = ( ua.match(/(ipad|iphone|ipod)/g) ? true : false );
		var android = ( ua.match(/android/i) ? true : false );
		var wx = ( ua.match(/micromessenger/i) ? true : false );
		// android_downloadurl = $("#android_downloadurl").val();
		android_downloadurl = 'https://api.lihua.com/static/app/lihua_app_android.apk';
		// android_downloadurl = 'https://api.lihua.com/static/app/lihua_app_6.0.0.apk';

		//此时还是微信页面，可以直接提示用户在浏览器打开
		if (wx) {
			if (iOS) {
				document.getElementById('iphone').style.display = 'block';
			} else if (android) {
			    document.getElementById('android').style.display = 'block';
			}
		}else{
			/**
			 * 此时已在浏览器页面打开页面
			 * **/
			if (iOS) {
				console.log("ios");
			    //之前已经尝试过Universal Links打开app失败了，此处不错尝试，直接打开appstore
				// window.location = ios_appstore_url;
			} else if (android) {
				console.log("android");
				//android需要尝试scheme方式打开app
				openAndroidClient(android_scheme_url);
			}
		}
		$("#downloadlnk").click(function(){
			if (iOS) {
				window.location = ios_appstore_url;
			} else if (android) {
				window.location = android_downloadurl;
			}
		})

		var errors = $("#error").val();

		$("#get_btn").click(function(){
			if(!!errors) return;
			$(".panel").show();
			$(".panel").css("display","flex");
		})

		$(".submit1").click(function () {
            var phone = $("#phone").val();
            var code  = $("#code").val();
            var sn  = $("#sn").val();
            if (phone && code) {
                $.post("/hongbao/index/login_voucher", {phone: phone, code: code, sn: sn}, function (ret) {
                    if (ret.code === 1) { 
						window.location.reload();
					} else { 
						alert(ret.msg); 
					} 
                });
            } else {
                alert("请填写手机号和验证码");
            }
            return false;
        });

		$(".use_lnk").click(function () {
			use_lnk_fn();
		});

        $("#getCode").click(function () {
            if (canGetCode) {
                var phone = $("#phone").val();
                if (checkPhone(phone)) {
                    timeOut();
                    getCode(phone);
                } else {
                    alert("请输入正确的手机号");
                }
            } else {
                alert("若未收到短信验证码，请稍后再试")
            }
        });
		$("#clickuse").click(function () {
			use_lnk_fn();
		})

		console.log(errors);
		if(!!errors){
			$(".panelerror").show();
			$(".panelerror").css("display","flex");
		}
		
	})

	function use_lnk_fn(){
		//判断当前平台
		var android_scheme_url = "lihuaapp://";
		var ios_appstore_url = "https://itunes.apple.com/cn/app/li-hua-kuai-can/id628351424";
		var ua = navigator.userAgent.toLowerCase();
		var iOS = ( ua.match(/(ipad|iphone|ipod)/g) ? true : false );
		var android = ( ua.match(/android/i) ? true : false );
		// alert(iOS);
		// alert(android);
		var applink, url;
		if (iOS) {
			// url = "https://www.lihua.com/newapp/"; //Universal Links
			// openIOSclient(url);
			window.location.href = "https://newapp.lihua.com/hongbao/index/download";
		} else if (android) {
			//因为此页面肯定在微信里面所以用不了微信的scheme
			window.location.href = "https://newapp.lihua.com/hongbao/index/download";
		}
	}

	function openAndroidClient(url) {
		window.location.href = url;
	}

	//倒计时
    function timeOut() {
        $("#getCode").text("60秒");
        var time = 60;
        setTimeOut = setInterval(function () {
            time--;
            $("#getCode").text(time + "秒");
            if (time === 0) {
                canGetCode = true;
                clearInterval(setTimeOut);
            }
        }, 1000);
    }

	//打开ios app软件
	function openIOSclient(url) {
		// alert(url);
		var ifr = document.createElement('iframe');
		ifr.src = url;
		ifr.style.display = 'none';
		document.body.appendChild(ifr);
		clearTimeout(t);
		t = setTimeout(function() {
			// alert(downloadurl);
		    window.location = url;
		}, 2000);
		window.onblur = function() {
		    clearTimeout(t);
		}
	}

    //获取地址栏参数
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    //获取验证码
    function getCode(phone) {
        canGetCode = false;
        $.post("https://newapp.lihua.com/api/sms/send", {mobile: phone, event: 'login'});
    }

    //验证手机号
    function checkPhone(phone) {
        var myreg = /^[1][0-9]{10}$/;
        return myreg.test(phone);
    }


</script>
</body>
</html>
